package com.pactera.service.system;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pactera.common.constants.Constants;
import com.pactera.common.utils.UUIDUtils;
import com.pactera.mapper.SysUserMapper;
import com.pactera.model.SysRole;
import com.pactera.model.SysUser;
import com.pactera.vo.user.UserReqVo;

@Service
public class SysUserService {
	
	@Autowired
	private SysUserMapper sysUserMapper;
	
	private static final Logger LOGGER = LoggerFactory.getLogger(SysUserRoleService.class);
	
	public SysUser getByAccount(String account) {
		SysUser sysUser = new SysUser();
		try {
			sysUser =  sysUserMapper.selectByAccout(account);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sysUser;
	}
	
	public SysUser getByMail(String mail) {
		SysUser sysUser = new SysUser();
		try {
			sysUser =  sysUserMapper.selectByMail(mail);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sysUser;
	}
	
	public SysUser getByPhone(String phone) {
		SysUser sysUser = new SysUser();
		try {
			sysUser =  sysUserMapper.selectByPhone(phone);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sysUser;
	}
	
	/**
	 * @Title: saveUserInfo 
	 * @Description: 保存用户信息
	 * @return Boolean
	 * @author LiuGuiChao
	 * @date 2019年1月12日 下午8:50:23 
	*/
	public Boolean saveUserInfo(UserReqVo userReqVo, String[] RoleIds) {
		LOGGER.info("####### SR-用户信息新增 Begin #######");
		int cnt = 0 ;
		try {
			SysUser sysUser = new SysUser();
			sysUser.setId(UUIDUtils.create());
			sysUser.setAccount(userReqVo.getAccount());
			sysUser.setMail(userReqVo.getMail());
			sysUser.setPassword(userReqVo.getPassword());
			sysUser.setMobilePhone(userReqVo.getMobilePhone());
			sysUser.setRealname(userReqVo.getRealname());
			sysUser.setRemark(userReqVo.getRemark());
			sysUser.setSex(userReqVo.getSex());
			sysUser.setCreateTime(new Date());
			sysUser.setCreateUid("123456");
			sysUser.setCreateUname("test用户新增测试");
			sysUser.setDisabled(userReqVo.getDisabled());
			cnt = sysUserMapper.insert(sysUser);
			
			String userId = sysUser.getId();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		LOGGER.info("####### SR-用户新增 End #######");
		return cnt > 0 ? true:false;
	}
}
